namespace Maple.Branch.Identity
{
    using System;
    using System.Linq;
    using System.Threading.Tasks;
    using IAppServices;
    using IServices;
    using Volo.Abp.DependencyInjection;

    [Dependency(TryRegister = true)]
    public class HttpClientUserRoleFindService : IUserRoleFindService, ITransientDependency
    {
        protected IIdentityUserAppService _userAppService { get; }

        public HttpClientUserRoleFindService(IIdentityUserAppService userAppService)
        {
            _userAppService = userAppService;
        }

        public virtual async Task<string[]> GetRolesAsync(Guid userId)
        {
            var output = await _userAppService.GetRolesAsync(userId);

            return output.Items.Select(r => r.Name).ToArray();
        }
    }
}
